home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 2 / Tech Arsenal 2 (Arsenal Computer).iso / clipper / s93bsp.exe / QBPROCS.PRG < prev    next >
Encoding:
Text File  |  1993-08-11  |  15.5 KB  |  742 lines

  1. procedure QBMESS
  2. *   Q B M E S S . P R G
  3. * Print a MSG and wait for key stroke
  4. PARAMETER MSG, colparam, waitime
  5. private MEM
  6. *    Last change:  MIB  11 Aug 93    4:40 pm
  7.  
  8. do case
  9. case PCOUNT()=0
  10.     MSG = "Press any key to continue..."
  11.     colparam = COLMENU
  12.     waitime = -1
  13. case PCOUNT()=1
  14.     colparam=colnorm
  15.     waitime=0
  16. case PCOUNT()=2
  17.     waitime=0
  18. endcase
  19.  
  20. @ QBMSGLIN,0 CLEAR to QBMSGLIN+1,79
  21. set color to (colparam)
  22. @ QBMSGLIN,centre(trim(MSG),79) say trim(MSG)
  23. set color to (colnorm)
  24. do case
  25. case waitime > 0
  26.     inkey(waitime)
  27.     @ QBMSGLIN,0 CLEAR to QBMSGLIN+1,79
  28. case waitime < 0
  29.     set cursor off
  30.     mem=" "
  31.     set color to (colpwd)
  32.     @ QBMSGLIN,0 get mem
  33.     read
  34.     set color to (colnorm)
  35.     @ QBMSGLIN,0 CLEAR to QBMSGLIN+1,79
  36.     set cursor on
  37. endcase
  38.  
  39. RETURN
  40.  
  41. ******************************************************************
  42.  
  43. procedure QBCLMESS
  44. *       Q B C L M E S S
  45. *       Clear the message box
  46.  
  47. set color to (colnorm)
  48. @ QBMSGLIN,0 CLEAR to QBMSGLIN+1,79
  49.  
  50. RETURN
  51.  
  52. ******************************************************************
  53.  
  54. function QBPROMPT
  55.  
  56. *   Q B P R O M P T . P R G
  57. *   Prompt user for single letter command
  58.  
  59. PARAMETER CMDS,MSG, CMDNO
  60. PRIVATE NCMDS, COLNO, I, MCHR
  61. store 1 to N1
  62. set message to QBMSGLIN+1 center
  63. if pcount()=1
  64.     MSG = "Select with first character, or "+chr(27)+" "+chr(26)+" and ┘"
  65. elseif pcount()=2
  66.     CMDNO = QBCHOICE
  67. endif
  68. MCHR = ""
  69.  
  70. ncmds = chrcount("|",CMDS)
  71. COLNO = centre(cmds+space(NCMDS),79)
  72.  
  73. CLEAR typeahead
  74. do QBCLMESS
  75. set color to (COLMENU)
  76. for I=1 to NCMDS
  77.     N2 = atnext("|",CMDS,I)
  78.  
  79.     @ QBMSGLIN, COLNO prompt substr(CMDS,N1,N2-N1) message MSG
  80.     MCHR = MCHR + substr(CMDS,N1,1)
  81.     COLNO = col() + 2
  82.     N1 = N2 + 1
  83. next
  84. menu to CMDNO
  85. QBKEY = lastkey()
  86. if CMDNO=0
  87.     GETOUT = .t.
  88.     QBCHOICE = 0
  89.     QBRESP="Q"
  90.     QBKEY = 27
  91. else
  92.     QBRESP = substr(MCHR,CMDNO,1)
  93.     QBCHOICE = CMDNO
  94.     GETOUT = .f.
  95. endif
  96. do QBCLMESS
  97.  
  98. RETURN CMDNO
  99.  
  100. ******************************************************************
  101.  
  102. procedure QBBOX
  103.  
  104. * Q B B O X
  105. Parameters WIDTH
  106. PRIVATE ulink, dlink, rcol, lcol
  107.  
  108. lcol = (79-width) / 2
  109. rcol = 79 - lcol
  110. dlink=chr(209)
  111. ulink=chr(207)
  112. @ 3,lcol say dlink
  113. @ 3,rcol say dlink
  114. @ 4,lcol TO 20,lcol
  115. @ 4,rcol TO 20,rcol
  116. @ 21,lcol SAY ulink
  117. @ 21,rcol SAY ulink
  118.  
  119. RETURN
  120.  
  121. ******************************************************************
  122.  
  123. procedure QBLAYOUT
  124.  
  125. * Q B L A Y O U T
  126.  
  127. * layout  general header routine
  128. PARAMETERS heading
  129.  
  130. CLEAR
  131. * @  1,0 to 1,79 double
  132. @ 21,0 to 21,79 double
  133. @  23,0 say qbtitle
  134. @  23,80-len(qbdate) say qbdate
  135. @  3,0 to 3,79 double
  136. set color to (COLHEAD)
  137. @ 22,centre(trim(heading),79) say trim(heading)
  138. set color to (COLNORM)
  139.  
  140. RETURN
  141.  
  142. ******************************************************************
  143.  
  144. procedure QBREAD
  145. *  Q B R E A D
  146. *  Routine to check whether a bunch of fields have been modified
  147. parameters MSG, MSG2
  148. PRIVATE mpos,mess
  149. MESS=trim(MSG)+" - Hit Esc to Abort"
  150. if pcount()<2
  151.     MSG2 = "Move:  , End: ┘ (field), PgDn (screen)"
  152. endif
  153. DO QBCLMESS
  154. SET color to (COLBRIGHT)
  155.  
  156. @ QBMSGLIN,centre(trim(mess),79) say trim(mess)
  157. if .not. empty(MSG2)
  158.     @ QBMSGLIN+1,centre(trim(MSG2),79) say trim(MSG2)
  159. endif
  160.  
  161. set color to (COLNORM)
  162. read
  163. GETOUT = (lastkey()=27)
  164. CHANGED = updated()
  165. DO QBCLMESS
  166.  
  167. return
  168.  
  169. ******************************************************************
  170.  
  171. procedure QBPUTL
  172.  
  173. *   Q B P U T L
  174. *   Used to output print lines and control page throws
  175. parameters LSKIP, LINE      && No lines to skip first, Output line
  176. private LCOUNT, PVAR
  177. LCOUNT = 1
  178.  
  179. if GETOUT
  180.     return
  181. endif
  182. *   Public variable references (defined amd released in QBPRCTL):
  183.  
  184. *   PAGENO => current page number
  185. *   PLENGTH => no lines to page
  186. *   PLINE => current line no
  187. *   PHEAD1...PHEADn => header text lines for each page
  188. *   PHEADn that are missing become line feeds
  189. *   PHEAD => no header lines
  190. *   PDEST => Screen, Printer, File
  191. *   PFOOT1...PFOOTn => footer text lines for each page
  192. *   PFOOT => no footer lines
  193. if LINE="PLENGTH"
  194.     PLENGTH = LSKIP
  195.     return
  196. endif
  197. if LINE="PWIDTH"
  198.     PWIDTH = LSKIP
  199.     return
  200. endif
  201. if LINE="EJECT"
  202.     PLINE = PLENGTH + 1
  203.     LINE=""
  204. endif
  205.  
  206. *       End of Page
  207.  
  208. if (PLINE + LSKIP)>PLENGTH
  209.  
  210.     if .not. PSTART
  211.         for LCOUNT=1 to PFOOT
  212.             PVAR = "PFOOT"+str(LCOUNT,1)
  213.             if type(PVAR)<>"C"         && Did we define it?
  214.                 ?
  215.             else
  216.                 EXEC = &PVAR
  217.                 ? &EXEC                  && Execute Macro for footer
  218.             endif
  219.         next
  220.         LCOUNT = 1
  221.         do case
  222.         case PDEST="S"
  223.             if QBYESNO("Continue listing? (Y/N)")="N"
  224.                 GETOUT = .t.
  225.                 return
  226.             endif
  227.             clear
  228.             @ 3,0 say ""
  229.         case PDEST="P"
  230.             eject
  231.         endcase
  232.     else
  233.         if PDEST="S"
  234.             clear
  235.             @ 3,0 say ""
  236.         endif
  237.         PLENGTH = PLENGTH - (PHEAD + PFOOT)
  238.         PSTART = .f.
  239.     endif
  240.  
  241.     do while LCOUNT<=PHEAD
  242.         PVAR = "PHEAD"+str(LCOUNT,1)
  243.         if type(PVAR)<>"C"         && Did we define it?
  244.             ?
  245.         else
  246.             if len(&PVAR)<PWIDTH-9 .and. LCOUNT=1
  247.                 ? &PVAR + space(PWIDTH-10-len(PHEAD1)) + "Page"+str(PAGENO,4)
  248.             else
  249.                 ? &PVAR
  250.             endif
  251.         endif
  252.         LCOUNT = LCOUNT + 1
  253.     enddo
  254.     PAGENO = PAGENO + 1
  255.     PLINE = 0
  256.     LCOUNT = 1
  257.  
  258. endif
  259.  
  260. for LCOUNT=1 to LSKIP
  261.     ?
  262. next
  263.  
  264. PLINE = PLINE + LSKIP
  265.  
  266. if len(LINE)>PWIDTH
  267.     LINE = substr(LINE,1,PWIDTH)
  268. endif
  269.  
  270. ?? LINE
  271.  
  272. return
  273.  
  274. ******************************************************************
  275.  
  276. procedure QBPUTH
  277.  
  278. *   Q B P U T H
  279. *   Used to define page headings
  280. parameters HEADNO, HLINE      && Heading lineno, head line
  281. private PVAR
  282.  
  283. *   Public variable references:
  284.  
  285. *   PAGENO => current page number
  286. *   PLENGTH => no lines to page
  287. *   PLINE => current line no
  288. *   PHEAD1...PHEADn => header text lines for each page
  289. *   PHEAD => no header lines
  290. *   PDEST => Screen, Printer, File
  291.  
  292. PVAR = "PHEAD"+str(HEADNO,1)
  293. &PVAR = HLINE
  294.  
  295. PHEAD = max(PHEAD+1,HEADNO)
  296.  
  297. return
  298.  
  299. ******************************************************************
  300.  
  301. procedure QBPUTF
  302.  
  303. *   Q B P U T F
  304. *   Used to define page and grand totals
  305. parameters FOOTNO, FLINE      && Footer lineno, Foot line
  306. private PVAR
  307.  
  308. *   Public variable references:
  309.  
  310. *   PAGENO => current page number
  311. *   PLENGTH => no lines to page
  312. *   PLINE => current line no
  313. *   PHEAD1...PHEADn => header text lines for each page
  314. *   PHEAD => no header lines
  315. *   PDEST => Screen, Printer, File
  316. *   PFOOT1...PFOOTn => footer text lines for each page
  317. *   PFOOT => np footer lines
  318.  
  319. PVAR = "PFOOT"+str(FOOTNO,1)
  320. &PVAR = FLINE
  321.  
  322. PFOOT = FOOTNO
  323.  
  324. return
  325.  
  326. ******************************************************************
  327.  
  328. procedure QBWIPE
  329.  
  330. *       QBWIPE
  331. *       Wipe out all the fields in a record
  332. DUMMY = ""
  333. N = fcount()
  334. declare FNAME[N], FTYPE[N], FWIDTH[N]
  335.  
  336. AFIELDS(FNAME, FTYPE, FWIDTH, DUMMY)
  337.  
  338. for I=1 to N
  339.  
  340.     do case
  341.     case FTYPE[I]$"CM"
  342.         NULVAR = " "
  343.     case FTYPE[I]="D"
  344.         NULVAR = ctod("")
  345.     case FTYPE[I]="N"
  346.         NULVAR = 0
  347.     case FTYPE[I]="L"
  348.         NULVAR = .f.
  349.     endcase
  350.     CURFLD = FNAME[I]
  351.     replace &CURFLD with NULVAR
  352. next
  353.  
  354. return
  355.  
  356. ******************************************************************
  357.  
  358. procedure QB2DATES
  359.  
  360. *       Q B 2 D A T E S
  361. *       get two dates if one is blank  set limits..
  362. parameters MESS, R1, C1, D1, R2, C2, D2
  363. if D1=ctod("01/1/87")
  364.     D1 = ctod("")
  365. endif
  366. if D2=ctod("31/12/99")
  367.     D2 = ctod("")
  368. endif
  369.  
  370. do while .t.
  371.     @ R1, C1 get D1 picture "@K"
  372.     @ R2, C2 get D2 picture "@K"
  373.     do QBREAD with MESS
  374.  
  375.     if D2=ctod("")
  376.         D2 = ctod("31/12/99")
  377.     endif
  378.  
  379.     do case
  380.     case GETOUT
  381.         exit
  382.     case D1>D2
  383.         do QBMESS with "First date is after Second",COLFLASH,3
  384.     case D1=ctod("")
  385.         D1 = ctod("01/01/87")
  386.         exit
  387.     otherwise
  388.         exit
  389.     endcase
  390. enddo
  391.  
  392. return
  393.  
  394. ******************************************************************
  395.  
  396. function QBMENU
  397.  
  398. *   Q B M E N U . P R G
  399. * Procedure to get menu choice from user -
  400. * returns both keystroke and choice no.
  401. PARAMETERS menuname, width
  402. PRIVATE scol, mrow, maxlen, lpos, cpos, nchar, m, i
  403. scol=5+(79-width)/2
  404. mrow=8
  405. maxlen=0
  406. i=0
  407. lpos=1
  408. qbkey=0
  409. if QBCHOICE=0
  410.     QBCHOICE=1
  411. endif
  412.  
  413. * SET exact off
  414. set message to 1 CENTER
  415. * SELECT 9
  416. set color to (COLMENU)
  417. use qbinfo index qbinfo
  418. set softseek on
  419. SEEK  trim(menuname)
  420. if ! eof()
  421.     DO WHILE (substr(qbinfkey,1,7)=menuname) .AND. (.NOT. eof())
  422.         i = i + 1
  423.         @ mrow, scol PROMPT trim(QBTEXT) MESSAGE trim(WHATITDOES)
  424.         mrow = mrow + 1
  425.         SKIP
  426.     ENDDO
  427. endif
  428. IF i=0
  429.     DO qbmess WITH "No valid menu choices available", colflash,5
  430.     qbkey = 27
  431.     qbchoice = 0
  432.     use
  433.     RETURN 0
  434. else
  435.     MENU to QBCHOICE
  436.     SEEK substr(menuname,1,7)+str(qbchoice,1)
  437.     qbproc = qbtext
  438.     use
  439. ENDIF
  440. if QBCHOICE=0
  441.     QBKEY=27
  442. endif
  443. set softseek off
  444.  
  445. set color to (COLNORM)
  446. * SET exact on
  447.  
  448. RETURN QBCHOICE
  449.  
  450. ******************************************************************
  451.  
  452. procedure QBPRCTL
  453.  
  454. *     Q B P R C T L
  455. *     Control Printing
  456. PARAMETERS  choice
  457. fname=space(8)
  458. public PAGENO, PHEAD, PFOOT, PSTART, PDEST
  459. PAGENO = 1
  460. PHEAD = 0
  461. PFOOT = 0
  462. PSTART = .t.
  463.  
  464. if GETOUT
  465.     close database
  466.     return
  467. endif
  468.  
  469. * If the choice is specified it just goes ahead and does it using the last part
  470. * of choice as the file name, if not you are asked which to use if it's a file
  471. * then you are prompted for the name.
  472.  
  473. do case
  474. case len(trim(choice))=0
  475.     PDEST=" "
  476.     SET console ON
  477.     SET alternate OFF
  478.     CHOICE = substr("SPFQ",QBPROMPT("Screen|Printer|File|Quit|","Choose output destination",1),1)
  479.     if CHOICE="Q"
  480.         GETOUT=.t.
  481.         return
  482.     endif
  483. case len(trim(choice))>2
  484.      fname=substr(choice,3,len(choice)-2)
  485. endcase
  486.  
  487. choice=substr(choice,1,1)
  488. IF choice$"PSF"
  489.     PDEST = CHOICE
  490.     do case
  491.     case CHOICE="S"
  492.         PLENGTH = 22
  493.         PWIDTH = 79
  494.     otherwise
  495.         PLENGTH = 55
  496.         PWIDTH = 132
  497.     endcase
  498.     PLINE = PLENGTH + 1
  499.     PHEAD = 0
  500. ENDIF
  501.  
  502. DO CASE
  503. CASE choice="S"
  504.     DO qbmess WITH "Preparing Report",colflash,0
  505. CASE  choice="P"
  506.     DO qbmess WITH "Printing Report",colflash,0
  507.     do while .not. isprinter()
  508.         ACTION = QBPROMPT("Continue|Quit|","Printer is not ready - correct and continue or Quit",1)
  509.         if ACTION=2 .or. QBRESP="Q"
  510.             GETOUT = .t.
  511.             return
  512.         endif
  513.     enddo
  514.     SET print ON
  515.     SET console OFF
  516.     ? TPSET1            && Begin print code
  517. CASE CHOICE="F"
  518.     IF len(choice)>1
  519.         fname = trim(substr(choice,3,len(choice-2)))
  520.     ELSE
  521.         DO qbclmess
  522.         @ QBMSGLIN, 26 SAY "Enter file name: " GET fname PICTURE "NNNNNNNN"
  523.         READ
  524.     ENDIF
  525.     if .not. "."$fname
  526.         fname = upper(trim(fname)) + ".TXT"
  527.     endif
  528.     DO qbmess WITH "Sending Report to file "+fname,colflash,0
  529.     SET alternate TO &fname
  530.     SET console OFF
  531.     SET alternate ON
  532. CASE choice="R"                     && Reset
  533.     SET print OFF
  534.     SET console ON
  535.     store "" to PHEAD1, PHEAD2, PHEAD3, PHEAD4, PHEAD5, PHEAD6, PHEAD7, PHEAD8, PHEAD9
  536.     DO CASE
  537.     CASE pdest="F"
  538.         ?
  539.         SET alternate OFF
  540.         CLOSE alternate
  541.     CASE pdest="P"
  542.         SET console OFF
  543.         EJECT
  544.         SET console ON
  545.         SET print OFF
  546.     CASE pdest="S"
  547.         ?
  548.         ?
  549.     ENDCASE
  550.     do QBMESS with FNAME+" - Press a key",colmenu,-1
  551.     DO qbclmess
  552. ENDCASE
  553. TPSET1=PSET2                && reset to system defaults
  554. RETURN
  555.  
  556. ******************************************************************
  557.  
  558. procedure QBLSTSUN
  559. *       Q B L S T S U N . P R G
  560. *       Find the date last Sunday
  561. PUBLIC lstsun
  562.  
  563. lstsun = date() - dow(date()) + 1
  564.  
  565. RETURN
  566.  
  567. ******************************************************************
  568.  
  569. procedure QBGETD
  570. *       Q B G E T D . P R G
  571. * get a date variable: qbrespd
  572.  
  573. PARAMETER MSG, default
  574. PRIVATE mpos
  575. mpos=(79-len(MSG))/2
  576. qbrespd=ctod(default)
  577.  
  578. SET confirm on
  579. do QBCLMESS
  580. @ QBMSGLIN,mpos SAY MSG GET qbrespd
  581. READ
  582. SET confirm off
  583.  
  584. RETURN
  585.  
  586. ******************************************************************
  587.  
  588. function QBYESNO
  589. parameters MSG
  590. private RETVAL
  591.  
  592. do QBCLMESS
  593. set color to (COLBRIGHT)
  594. set cursor off
  595. @ QBMSGLIN,centre(trim(MSG),79) say trim(MSG)
  596.  
  597. RETVAL = " "
  598. do while .not. RETVAL$"YN"
  599.     RETVAL = upper(chr(inkey()))
  600. enddo
  601. do QBCLMESS
  602. set cursor on
  603.  
  604. return RETVAL
  605.  
  606. ******************************************************************
  607.  
  608. function CENTRE
  609. *       Returns column position for Centred heading
  610. parameters cTEXT, WIDTH
  611.  
  612. if pcount()=1
  613.     WIDTH = 80
  614. endif
  615.  
  616. COLPOS = max(int((WIDTH-1-len(cTEXT)) / 2),0)
  617.  
  618. return COLPOS
  619.  
  620. ******************************************************************
  621.  
  622. procedure QBADBLNK
  623.  
  624. *   Q B A D B L N K . P R G
  625. * Routine to append blank records
  626. PARAMETERS nrecs
  627. PRIVATE i, adstr
  628.  
  629. * i = recsize()*nrecs
  630. * IF i>diskspace()
  631. *     adstr = "You have run out of disc space!!"
  632. *     DO qbmess WITH adstr,colflash,0
  633. *     WAIT
  634. *    DO qbquit
  635. * ENDIF
  636.  
  637. adstr = "Please wait - adding "+str(nrecs,4)+" records"
  638.  
  639. DO qbmess WITH adstr,colflash,0
  640.  
  641. i=1
  642. DO WHILE i<=nrecs
  643.     i = i + 1
  644.     APPEND BLANK
  645. ENDDO
  646. DO qbmess WITH " ",colnorm,0
  647.  
  648. return
  649.  
  650. ******************************************************************
  651. function seekit
  652. parameters cText
  653. seek cText
  654. return ( ! eof() )
  655.  
  656. *******************************************************************
  657. function blank
  658. parameters xValue
  659. private xReturn
  660.  
  661. do case
  662. case type( "xValue" ) == "C"
  663.     xReturn = space( len( xValue ) )
  664. case type( "xValue" ) == "N"    
  665.     xReturn = 0
  666. case type( "xValue" ) == "L"
  667.     xReturn = .f.
  668. case type( "xValue" ) == "D"
  669.     xReturn = ctod("")
  670. endcase
  671.  
  672. return xReturn
  673.  
  674. *******************************************************************
  675. function chrcount
  676. parameters cChar, cString
  677. private iReturn, i
  678. iReturn = 0
  679.  
  680. for i=1 to len( cString )
  681.     if substr( cString, i, 1 ) == cChar
  682.         iReturn = iReturn + 1
  683.     endif 
  684. next
  685.  
  686. return iReturn
  687.  
  688. *******************************************************************
  689. function ceiling
  690. parameters nValue
  691. private iReturn, i
  692. iReturn = 0
  693.  
  694. iReturn = int( nValue + 0.999 )
  695.  
  696. return iReturn
  697.  
  698. *******************************************************************
  699. function isDrive
  700. parameters cDrive
  701.  
  702. return .t.
  703.  
  704. *******************************************************************
  705. function atnext
  706. parameters cChar, cString, nOcc
  707. private iReturn, i, iCount
  708. store 0 to iReturn, iCount
  709.  
  710. begin sequence
  711. for i=1 to len( cString )
  712.     if substr( cString, i, 1 ) == cChar
  713.         iReturn = i
  714.         iCount = iCount + 1
  715.         if iCount >= nOcc
  716.             break
  717.         endif                          && if iCount >= nOcc
  718.     endif                              && if substr( cString, i, 1 ) == cChar
  719. next             
  720. iReturn = 0
  721. end
  722. return iReturn
  723.  
  724. *******************************************************************
  725. function center
  726. parameters cString, nWidth
  727. private iLen, cReturn
  728.  
  729. if type( "nWidth" ) <> "N"
  730.     nWidth = 80
  731. endif                                  && if type( "nWidth" ) <> "N"
  732. iLen = int( ( nWidth - len( alltrim( cString ) ) ) / 2 )
  733.  
  734. if iLen < 0
  735.     cReturn = substr( cString, 1, nWidth )
  736. else
  737.     cReturn = space( iLen ) + alltrim( cString )
  738. endif                                  && if iLen < 0
  739.  
  740. return cReturn
  741.  
  742.